﻿<?php 
include 'PublicdetailController.php';
	
class OrderController extends PublicdetailController {
    public $idnguoidung;
    public $nguoidung;
    public function init() {
		     $this->initValue ();
			 $this->idnguoidung = $this->TblUserbyId[0]['id'];
             $this->nguoidung = $this->TblUserbyId[0]['name'];	
		}
	public function newAction() {
		$roomModel = new Model_Room();
		$this->view->pricing = json_encode($roomModel->getPricing());
	}
	public function printAction() {
		$model = new Model_Order();
		$id = $_GET['id'];
		$order = $model->load($id);
		$this->view->order = $order;
	}
	public function listAction() {
		$page = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rows = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 1;
		$sort = isset ( $_POST ['sort'] ) ? strval ( $_POST ['sort'] ) : 'id';
		$order = isset ( $_POST ['order'] ) ? strval ( $_POST ['order'] ) : 'asc';
		$offset = ($page - 1) * $rows;
		$this->_helper->layout ()->disableLayout ();
		$options = array(
			'page' => $page,
			'rows' => $rows,
			'sort' => $sort,
			'order' => $order,
			'offset' => $offset,
			'kw' => @$_POST['kw'],
			'd' => @$_POST['d']
		);
		$tableModel = new Model_Order ();
        $jsonObj = json_encode ( $tableModel->getItems ( $options ) );
		return $this->view->jsonObj = $jsonObj;
	}
	public function editAction() {
		$roomModel = new Model_Room();
		$this->view->pricing = json_encode($roomModel->getPricing());
		$model = new Model_Order();
		$id = $_GET['id'];
		$order = $model->load($id);
		$this->view->order = $order;
	}
	public function createAction() {
		$this->_helper->layout ()->disableLayout ();
		$model = new Model_Order();
		$data = $_POST;
		$data['createdBy'] = $this->nguoidung;
		$data['creeatedById'] = $this->idnguoidung;
		$data['created'] = date('Y-m-d H:i:s'); 
		$model->create($data);
		die();
	}
	public function updateAction() {
		$this->_helper->layout ()->disableLayout ();
		$model = new Model_Order();
		$data = $_POST;
		$model->update($data);
		die();
	}
	
	public function calculatetypesAction() {
		$this->_helper->layout ()->disableLayout ();
		echo json_encode(array(
			array('label' => 'Theo ngày', 'value' => '1'),
			array('label' => 'Theo giờ', 'value' => '2'),
			array('label' => 'Theo ngày và giờ', 'value' => '3')
		));
		die();
	}
	
	public function deleteAction() {
		$this->_helper->layout ()->disableLayout ();
		$model = new Model_Order();
		if(@$_REQUEST['id'])
			$model->delete($_REQUEST['id']);
		die();
	}
}
